-
-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a few cases commands to fun.py to output a string in a specific case. #1455
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a code review, didn't test this yet.
bot/exts/fun/fun.py
Outdated
@@ -51,6 +51,21 @@ def _get_random_die() -> str: | |||
die_name = f"dice_{random.randint(1, 6)}" | |||
return getattr(Emojis, die_name) | |||
|
|||
@staticmethod | |||
async def _clean_fun_cog_text(ctx: Context, text: str, conversion_func: Callable[[str], str]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should not do the sending part, let it just clean the text & embed and return them as a tuple.
Also, the fun_cog
in the function name is a redundant since it's a private function of the Fun
cog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey!
Thanks for the feedback. I've changed the name and the function now returns said tuple.
I'm struggling to put the BadArgument check in self._clean_text
for some reason. I've now got the raise BadArgument added though and it's working. But I don't like the repeating of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I haven't seen these before.
One final sweep, and should be good.
|
||
@commands.command(name="pascalcase", aliases=("pcase", "pascal",)) | ||
async def pascalcase_command(self, ctx: Context, *, text: str | None) -> None: | ||
"""Attempts to convert the provided string to pascalCase.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i'm not mistaken, it's the other way around where PascalCase
should be pascalCase
and CamelCase
should be camelCase
So both docstrings & conversion functions need to be switched
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cant believe I had them the wrong way around hey. Fixed in both files now xD
return "_".join( | ||
text.split() | ||
) | ||
converted_text, embed = await self._clean_text(ctx, text, conversion_func) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit
converted_text, embed = await self._clean_text(ctx, text, conversion_func) | |
cleaned_text, embed = await self._clean_text(ctx, text, conversion_func) |
Since the function's name indicates "cleaning" rather than "converting"
"""Attempts to convert the provided string to pascalCase.""" | ||
text = helpers.neutralise_string(text) | ||
def conversion_func(text: str) -> str: | ||
"""Converts the provided string to pascalCase.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same note here for the docstring about the pascal & camel case notation
def conversion_func(text: str) -> str: | ||
"""Converts the provided string to CamelCase.""" | ||
return "".join( | ||
word[0].upper()+word[1:] for word in text.split() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a native way of doing this
word[0].upper()+word[1:] for word in text.split() | |
word.capitalize() for word in text.split() |
def conversion_func(text: str) -> str: | ||
"""Converts the provided string to pascalCase.""" | ||
return "".join( | ||
word[0].upper()+word[1:] if i != 0 else word for i, word in enumerate(text.split()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing about the usage of capitalize
here
Closing this because of the source branch change. |
Relevant Issues
Closes #707 if approved.
Description
pascalCase, CamelCase, snake_case, SCREAMING_SNAKE_CASE
.pascalcase aliases [.pascal .pcase]
.camelcase aliases [.camel .ccase]
.snakecase alias [.scase]
.screamingsnakecase aliases [.screamsnake .ssnake .screamingsnake]
Did you: